﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HNQXYJ.Model;
using HNQXYJ.BLL;

namespace HNQXYJ.HN_City
{
    public partial class CountyUpdate : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int id = Convert.ToInt32(Request["id"]);
                HCounty county = new CountyBLL().GetCountyById(id);
                if (county != null)
                {
                    this.txtCountyName.Text = county.Name;
                    this.city.Value = this.HidCity.Value;
                    this.txtCountyCode.Text = county.SelfCode;
                    this.txtLng.Text = county.Lng.ToString();
                    this.txtLat.Text = county.Lat.ToString();
                }
 
            }
        }

        protected void add_Click(object sender, ImageClickEventArgs e)
        {
            int id = Convert.ToInt32(Request["id"]);
            HCounty county = new CountyBLL().GetCountyById(id);
            county.ID = id;
            county.Name = this.txtCountyName.Text.Trim();
            county.ParentCode =this.HidCity.Value;
            county.SelfCode = this.txtCountyCode.Text.Trim();
            county.Lng = Convert.ToDouble(this.txtLng.Text.Trim());
            county.Lat = Convert.ToDouble(this.txtLat.Text.Trim());

            int res = new CountyBLL().UpdateCounty(county);
            if (res > 0)
            {
                Response.Redirect("CountyMgr.aspx");
            }
        }

        protected void reset_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("CountyMgr.aspx");
        }
    }
}